package com.core.androidlearndemo.livedata;

import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.core.androidlearndemo.R;

public class LiveDataMainActivity extends AppCompatActivity {

    private NameViewModel nameViewModel;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_livedata);
        nameViewModel = ViewModelProviders.of(this).get(NameViewModel.class);

        Observer<String> nameObserver = new Observer<String>() {
            @Override
            public void onChanged(@Nullable String s) {
                Log.d("11111",s);
            }
        };
        nameViewModel.getMutableLiveData().observe(this,nameObserver);
        nameViewModel.getMutableLiveData().setValue("测试");
    }
}
